<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      思路：利用数字的方式，存储26个字母出现的次数，然后遍历t再-- ，如果最后数组中有大于1的，就return false
      */
      var isAnagram = function (s, t) {
        let map = new Map()
        for (let i = 0; i < s.length; i++) {
          if (!map.has(s[i])) {
            map.set(s[i], 1)
          } else {
            map.set(s[i], map.get(s[i]) + 1)
          }
        }
        for (let i = 0; i < t.length; i++) {
          if (!map.has(t[i])) return false
          let temp = map.get(t[i])
          if (temp <= 0) return false
          map.set(t[i], temp - 1)
        }
        for (let [key, value] of map) {
          if (value>0) return false
        }
        return true
      }
      console.log(isAnagram('ab', 'a'))
    </script>
  </body>
</html>
